package pure.engine.world 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.display.TriangleCulling;
	import flash.events.Event;
	import flash.utils.Dictionary;
	import pure.engine.model.Model2D;
	import pure.engine.model.Renderer;
	import pure.engine.core.ns_despair;
	
	use namespace ns_despair
	
	/**
	 * 残像
	 * [Author] - PURE
	 * 
	 */
final public class Mirror extends Sprite 
{
	
	
	/**
	 * 更新
	 * 
	 * [Hint] - 调整残像位置
	 */
	final ns_despair function update(tx:Number, ty:Number):void
	{
		this.x += tx;
		this.y += ty;
	}
	
	
	/**
	 * 重新排序
	 */
	final ns_despair function needSort():void
	{
		m_layer.addNeedSortMirror(this);
	}
	
	
	/**
	 * 毁灭
	 * 
	 * [Hint] - 针对单体
	 */
	final ns_despair function destroy():void
	{
		if (m_layer)
		{
			m_layer.removeMirror(this);
		}
		recycle();
	}
	
	
	/**
	 * 回收
	 */
	final ns_despair function recycle():void
	{
		m_layer = null;
		this.filters = null;
		while (this.numChildren)
		{
			this.removeChildAt(0);
		}
		cachedMirrors[m_numMirror++] = this;
	}
	
	
	/**
	 * 获取
	 */
	ns_despair static function getMirror():Mirror
	{
		if (m_numMirror > 0)
		{
			m_numMirror--;
			return cachedMirrors.pop();
		}
		return new Mirror();
	}
	
	
	
	//======================
	// Member
	//======================
	

	ns_despair static var cachedMirrors:Vector.<Mirror> = new Vector.<Mirror>();

	ns_despair static var m_numMirror:int;
	
	ns_despair var m_layer:Layer;
	
	public var m_id:int;
	
	public var cachedIndex:int;
	
}
}